package com.company.eos.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.eos.common.util.PageUtils;
import com.company.eos.mapper.AmectTypeMapper;
import com.company.eos.domain.AmectType;
import com.company.eos.service.AmectTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author: Song, Wei
 * @date: 2022-03-20
 */
@Service
@Slf4j
public class AmectTypeServiceImpl extends ServiceImpl<AmectTypeMapper, AmectType>
        implements AmectTypeService {

    @Autowired
    private AmectTypeMapper amectTypeMapper;

    /**
     * 查询全部罚款类型
     *
     * @return
     */
    @Override
    public PageUtils searchAllAmectType(HashMap param) {
        ArrayList<HashMap> list = amectTypeMapper.searchByPage(param);
        long count = amectTypeMapper.searchTypeCount(param);
        int start = (Integer) param.get("start");
        int length = (Integer) param.get("length");
        return new PageUtils(list, count, start, length);
    }

    /**
     * 查询全部罚款类型
     *
     * @return
     */
    @Override
    public ArrayList<AmectType> searchAmectType() {
        return amectTypeMapper.searchAllAmectType();
    }

    @Override
    public int insert(BigDecimal money, String type) {
        AmectType amectType = new AmectType();
        amectType.setMoney(money);
        amectType.setType(type);
        amectType.setSystemic(0);
        return amectTypeMapper.insert(amectType);
    }

    @Override
    public int update(BigDecimal money, String type) {
        AmectType amectType = new AmectType();
        amectType.setMoney(money);
        amectType.setType(type);
        return amectTypeMapper.update(amectType, Wrappers.lambdaQuery(AmectType.class)
                .eq(AmectType::getType, amectType.getType()));
    }

    @Override
    public int delete(Integer[] ids) {
        int count = 0;
        for (Integer id : ids) {
            count += amectTypeMapper.delete(Wrappers.lambdaQuery(AmectType.class)
                    .eq(AmectType::getId, id)
                    .ne(AmectType::getSystemic, 1));
        }
        return count;
    }

    @Override
    public HashMap searchById(int amectTypeId) {
        HashMap map = amectTypeMapper.searchById(amectTypeId);
        return map;
    }
}
